<template>
  <div>
    <h1 @click="findAllOrder">订单管理</h1>
    <div>
      <el-table
        :data="orderList"
        style="width: 100%;">
        <el-table-column
          prop="id"
          label="id"
          width="180" v-if="false">
        </el-table-column>
        <el-table-column
          prop="orderNumber"
          label="订单号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          width="180">
        </el-table-column>
        <el-table-column
          prop="totalPrice"
          label="总金额"
          width="180">
        </el-table-column>
        <el-table-column
          prop="unikeName"
          label="姓名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="uaddr"
          label="取餐地址"
          width="180">
        </el-table-column>
        <el-table-column
          prop="offTime"
          label="取餐时间"
          width="180">
        </el-table-column>
        <el-table-column
          prop="info"
          label="备注"
          width="180">
        </el-table-column>
        <el-table-column
          prop=""
          label="操作"
          width="300">
          <template slot-scope="scope">
            <a type="text" style="color: #3a6ed5" v-if="scope.row.status===0">未支付</a>
            <a type="text" style="color: #aa0dc6" v-if="scope.row.status===1">已支付</a>
            <a type="text" style="color: #0a710a" v-if="scope.row.status===3">已完成</a>
            <el-button type="success"  @click="refund(scope.row.id,1)"v-if="scope.row.status===4">拒绝退款</el-button>
            <el-button type="danger"  @click="refund(scope.row.id,5)"v-if="scope.row.status===4">确认退款</el-button>
            <a type="text" style="color: red" v-if="scope.row.status===5">已退款</a>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="pageVo.current"
        :total="pageVo.total"
        :page-sizes="[1,20,30,50]"
        :page-size.sync="pageVo.size"
        background
        layout="prev, pager, next"
        @current-change="currentChange"
        @size-change="handleSizeChange"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "Order",
  data(){
    return {
      orderList: [{
        id: '',
        status: '',
        totalPrice:'',
        orderNumber: '',
        unikeName: '',
        uaddr: '',
        uid: '',
        createTime: '',
        offTime: '',
        info: ''
      }],

      pageVo: {
        current: 1,
        size: 7,
        total: 0
      }
    }
  },
  created() {
    this.findAllOrder()

  },
  methods: {
    //处理退款
    refund(id,status){
      this.$axios({
        method: 'get',
        url: '/admin/refund',
        params: {
          id,
          status
        }
      }).then(res => {
        if (res.data.code == 2000){
          alert('成功')
          this.findAllOrder()
        }else {
          alert('失败')
        }
      })
    },
    handleSizeChange(val){
      this.pageVo.size = val
      this.findAllOrder()
    },
    currentChange(val){
      this.pageVo.current=val
      this.findAllOrder()
    },
    findAllOrder(){
      this.$axios({
        method: 'post',
        url: '/admin/findAllOrder',
        data: this.pageVo
      }).then(res => {
        this.pageVo.total = parseInt(res.data.data.data.total)
        console.log(this.pageVo.total)
        this.orderList = res.data.data.data.records
      })
    }
  }
}
</script>

<style scoped>

</style>
